/*!
 @header
 @abstract    ICShowView.h
 @discussion  ICShowView处理如下两个问题：
 1、提示框
 2、提示之后执行某个操作
 3、多不执行
 4、执行某个方法时显示进度
 @updated     2013-04-23
 @author      Fox
 @version     1.0.0
 */

#import "ICShowView.h"
#import "MBProgressHUD.h"

#define DEFAULTDURATION         2.0


@implementation ICShowView

#pragma mark - Public methods




+ (void)showMBAlertView:(UIView *) currentView
                message:(NSString *) message
               duration:(float) duration
{
    MBProgressHUD *hud=[[MBProgressHUD alloc] initWithView:currentView];
    hud.color = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1];
    hud.detailsLabelColor  = [UIColor blackColor];
   // hud.activityIndicatorColor = MAINCOLOR;
    hud.labelColor = [UIColor blackColor];
    [currentView addSubview:hud];
    [hud setMode:MBProgressHUDModeText];
    if (message.length > 10) {
        hud.detailsLabelText = message;
        hud.detailsLabelFont=[UIFont boldSystemFontOfSize:16];
    }else{
        hud.labelText=message;
        hud.labelFont=[UIFont boldSystemFontOfSize:16];
    }
    hud.margin = 25.f;
    hud.yOffset = 100.f;
    hud.removeFromSuperViewOnHide=YES;
    [hud show:YES];
    [hud hide:YES afterDelay:duration];
    
}


+ (void)showMBAlertView:(UIView *) currentView
                message:(NSString *) message
{
    if ([message isEqualToString:@"已停号"]) {
        [ICShowView showMBAlertView:currentView message:@"已停号，请选择其他科室" duration:3.0];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"GoToNextRegisterCol" object:nil];
    }
    else
    {
        [ICShowView showMBAlertView:currentView message:message duration:DEFAULTDURATION];
    }
    
}

+ (void)showHUDAddedTo:(UIView *)targtView withText:(NSString *)text{
    
    MBProgressHUD *hud=[[MBProgressHUD alloc] initWithView:targtView];
    hud.dimBackground = YES;

   hud.color = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
    hud.detailsLabelColor  = [UIColor grayColor];
    hud.activityIndicatorColor = [UIColor grayColor];
    hud.labelColor = [UIColor grayColor];
    
    [targtView addSubview:hud];
    

//    [hud setMode:MBProgressHUDModeText];
    if (text.length > 10) {
        hud.detailsLabelText = text;
        
    }else{
        hud.labelText=text;
    }
    hud.removeFromSuperViewOnHide=YES;
    [hud show:YES];
   
}


+ (void)showMBAlertViewWithMessage:(NSString *) message
{
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    [ICShowView showMBAlertView:keyWindow message:message];
}

+ (void)showMBDownAlertViewWithMessage:(NSString *)message{
    
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    MBProgressHUD *hud=[[MBProgressHUD alloc] initWithView:keyWindow];
    hud.color = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1];
    hud.detailsLabelColor  = [UIColor grayColor];
    //hud.activityIndicatorColor = MAINCOLOR;
    hud.labelColor = [UIColor grayColor];
    [keyWindow addSubview:hud];
    [hud setMode:MBProgressHUDModeCustomView];
    if (message.length > 10) {
        hud.detailsLabelText = message;
    }else{
        hud.labelText=message;
    }
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] ;
    hud.removeFromSuperViewOnHide=YES;
    [hud show:YES];
    [hud hide:YES afterDelay:1];

    
}

/*!
 @method
 @abstract      弹出系统自带的Alter，过一段时间结束
 @discussion    去除时间参数和目标视图，时间默认为0.3秒，视图默认为window
 
 @param     message            需要显示的信息
 */
+ (void)showUIAlertViewWithMessage:(NSString *) message{
    NSString *newmessage = [NSString stringWithFormat:@"\n%@",message];
    UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@""
                                                    message:newmessage
                                                   delegate:nil
                                          cancelButtonTitle:nil
                                          otherButtonTitles:nil, nil] ;
    [alter show];
    [alter performSelector:@selector(dismissWithClickedButtonIndex:animated:) withObject:nil afterDelay:1.0];
}



+ (void) showMBAlertView:(UIView *) currentView
                 message:(NSString *) message
                duration:(float) duration
         completionBlock:(dispatch_block_t) completion
{
    //弹出MB对话框，过一段时间结束,完成执行
    MBProgressHUD *hud=[[MBProgressHUD alloc] initWithView:currentView];
    hud.color = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1];
    hud.detailsLabelColor  = [UIColor grayColor];
    //hud.activityIndicatorColor = MAINCOLOR;
    hud.labelColor = [UIColor grayColor];
    [currentView addSubview:hud];
    [hud setMode:MBProgressHUDModeText];
    if (message.length > 10) {
        hud.detailsLabelText = message;
    }else{
        hud.labelText=message;
    }
    hud.margin=25.f;
    hud.yOffset=100.f;
    [hud showAnimated:NO whileExecutingBlock:^{
        sleep(duration);
    } completionBlock:^{
        [hud removeFromSuperview];
        completion();
    }];
}

+ (void) showMBAlertView:(UIView *) currentView message:(NSString *) message whileExecutingBlock:(dispatch_block_t)block completionBlock:(dispatch_block_t) completion
{
    //同步请求
    //弹出MB对话框，在方法执行期间显示
    MBProgressHUD *hud=[[MBProgressHUD alloc] initWithView:currentView];
    hud.color = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1];
    hud.detailsLabelColor  = [UIColor grayColor];
    //hud.activityIndicatorColor = MAINCOLOR;
    hud.labelColor = [UIColor grayColor];
    hud.labelText=message;
    
    [currentView addSubview:hud];
    [hud showAnimated:YES whileExecutingBlock:block completionBlock:^{
        [hud removeFromSuperview];

        completion();
    }];
}




@end
